package com.trace.framework.di;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.trace.action.BookAction;
import com.trace.action.MessageAction;
import com.trace.action.UserAction;
import com.trace.dao.*;
import com.trace.dao.impl.*;
import com.trace.service.*;
import com.trace.service.impl.*;

public abstract class BeanFactory {

	private static Injector injector = null;

	static void create() {
		// TODO
		injector = Guice.createInjector(new AbstractModule() {

			@Override
			protected void configure() {

				bind(BookDao.class).to(BookDaoImpl.class);
				bind(BorrowBookDao.class).to(BorrowBookDaoImpl.class);
				
				bind(BookManager.class).to(BookManagerImpl.class);
				bind(BorrowBookManager.class).to(BorrowBookManagerImpl.class);
				
				bind(BookAction.class);
				bind(MessageAction.class);
				bind(UserAction.class);
				
			}
			
		});
	}
	
	static void destroy() {
		injector = null;
	}
	
	public static <T> T getBean(final Class<T> clazz) {
		return injector.getInstance(clazz);
	}
}
